package com.nbot.server.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nbot.server.domain.TransmissstationDO;
import com.nbot.server.service.TransmissstationService;
import com.nbot.server.util.PageUtils;
import com.nbot.server.util.Query;
import com.nbot.server.util.R;
import com.nbot.server.annotation.Log;

/**
 * 
 *
 * @author nbot
 * @email nbot@163.com
 * @date 2018-07-19 15:26:00
 */

@Controller
@RequestMapping("/server/transmissstation")
public class TransmissstationController {
    @Autowired
    private TransmissstationService transmissstationService;

    @GetMapping()
    @RequiresPermissions("server:transmissstation:transmissstation")
    String Transmissstation() {
        return "server/transmissstation/transmissstation" ;
    }

    @ResponseBody
    @Log("查看")
    @GetMapping("/list")
    @RequiresPermissions("server:transmissstation:transmissstation")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<TransmissstationDO> transmissstationList = transmissstationService.list(query);
        int total = transmissstationService.count(query);
        PageUtils pageUtils = new PageUtils(transmissstationList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("server:transmissstation:add")
    String add() {
        return "server/transmissstation/add" ;
    }

    @GetMapping("/edit/{autoid}")
    @RequiresPermissions("server:transmissstation:edit")
    String edit(@PathVariable("autoid") String autoid, Model model) {
            TransmissstationDO transmissstation = transmissstationService.get(autoid);
        model.addAttribute("transmissstation" , transmissstation);
        return "server/transmissstation/edit" ;
    }

    /**
     * 保存
     */
    @Log("保存")
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("server:transmissstation:add")
    public R save(TransmissstationDO transmissstation) {
        if (transmissstationService.save(transmissstation) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @Log("修改")
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("server:transmissstation:edit")
    public R update(TransmissstationDO transmissstation) {
            transmissstationService.update(transmissstation);
        return R.ok();
    }

    /**
     * 删除
     */
    @Log("删除")
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("server:transmissstation:remove")
    public R remove( String autoid) {
        if (transmissstationService.remove(autoid) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @Log("批量删除")
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("server:transmissstation:batchRemove")
    public R remove(@RequestParam("ids[]") String[]autoids) {
            transmissstationService.batchRemove(autoids);
        return R.ok();
    }

}
